home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10030 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  70 lines

  1. Path: sparc13.ncu.edu.tw!s3032089
  2. From: s3032089@sparc13.ncu.edu.tw (Alexander PeaceLand)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Do you see what is wrong?
  5. Date: Fri, 15 Mar 1996 09:32:28 GMT
  6. Organization: NCU ME
  7. Message-ID: <s3032089.14.3149392B@sparc13.ncu.edu.tw>
  8. References: <4i72h6$2d4@blaze.cs.jhu.edu>
  9. NNTP-Posting-Host: @140.115.65.133
  10.  
  11. >Can someone point out what is wrong with this snippet of code? 
  12. >The problem is that I get a segmentation fault(core dumped) error when I 
  13. >hit ^d to send end of file.  the error occurs at the place specified in 
  14. >the code.  I would appreciate any/all ideas and any fixes that you might 
  15. >suggest.  This was compiled on a system running some flavor of UNIX (not 
  16. >sure which)
  17.  
  18.  
  19. >#include <stdio.h>
  20. >#include <stdlib.h>
  21. >#include <math.h>
  22.  
  23. >#define         SIZE    200
  24.  
  25. >int closest(float [], float [], int [], float [], int);
  26. >float distance(float, float, float, float);
  27.  
  28. >void main()
  29. >{
  30. >float           xtemp, ytemp, Xposition[SIZE], Yposition[SIZE], totalLength[1];
  31. >int             j = -1, n, i, distance, nextCoord, current = 0, status[SIZE];
  32.  
  33. >totalLength[1] = 0;
  34.  
  35. >/* variables not used in this section are used in other non-relevant 
  36. >parts of the code */
  37.  
  38. >printf("Enter coordinates in the form: x y\n ");
  39.  
  40. >for( n = 0; n < SIZE; n++, j++ ) {
  41. >        if( scanf("%f%f", &xtemp, &ytemp) != EOF) 
  42.              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  43.              I don't know if scanf could used like this.
  44. But I have found that when your data formats you pass to scanf is 
  45. different from the one you assigned in scanf, the scanf will be DAMAGED!
  46. (I use Turbo C 2.0)
  47. Especailly in loop, when the scanf damaged, scanf will not wait for your
  48. input anymore.
  49.  
  50. >                {
  51. >                Xposition[n] = xtemp;
  52. >                Yposition[n] = ytemp; 
  53. >                }
  54. >        else    {
  55. >                printf("Done entering Numbers");  
  56. >                n = SIZE; 
  57. >                printf("\n%f %f", Xposition[j], Yposition[j]);
  58. >                }  /*  <== I get a core dump right here. _after_ executing the 
  59. >stuff in the else statemnet */ 
  60. >        } 
  61. >}
  62.  
  63.  
  64. o----------------------------------------------------------o
  65. |   (''')                                                  |
  66. |  ( 0 0 )    E-mail address : s3032089@sparc13.ncu.edu.tw |
  67. |   -----                                                  |
  68. |   |||||                      - Alexander PeaceLand -     |
  69. o----------------------------------------------------------o
  70.